<?php

/*

  Action - Attack	$6

  +1 Buy; +$2
  Each other player discards down to 3 cards in hand.
  While this is in play, when you buy a card, +1 VP token.

 */

class Goons extends Card implements iAction, iKingdom, iAttack, iProsperity, iReactingCard {

    private $reactConditions;

    public function __construct() {
        parent::__construct("Goons", 6);
        $this->undoPlay = false;
        $this->undoBuy = true;
        
        $this->reactConditions = new ReactionConditions();
        $this->reactConditions->action = array(Buy);
        $this->reactConditions->actor = array(Yourself);
        $this->reactConditions->cardLocation = array(PlayArea);
        $this->reactConditions->limit = ForEachCard;
        $this->reactConditions->isMandatory = true;
    }
    
     public function getDisplayName($quantity = 1) {
        if ($quantity == 1) {
            return "Goons";
        }
        return $quantity . " Goons";
    }

    public function getDescription() {
        return array(
            "+1 Buy",
            "+$2",
            "Each other player discards down to 3 cards in hand.",
            "While this is in play, when you buy a card, +1 VP token.");
    }

    public function play(Game $game, $isRealCard) {

        $game->addBuys(1);
        $game->addMoney(new Price(2));
        ScreenDisplay::addScreenMessage($game, true, "get +1 buy and +2$ ", "gets +1 buy and +2$ ");

        $game->setPhase(Phase_Sleep);

        $game->attack($this);

        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {
            $playHandOther = $game->getPlayHand($name);
            $playHandSize = sizeof($playHandOther);
            if ($playHandSize > 3) {

                $cards_to_discard = $playHandSize - 3;

                $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHandOther, $cards_to_discard, $cards_to_discard, null, "Choose $cards_to_discard cards to discard", $name, true);
            }
        }

        //the waiting function
        $users_replies = MySocket::getUsersReplies($game);
        foreach ($users_replies as $name => $output) {
            ScreenDisplay::addScreenMessage($game, true, "discard " . nicePrint($output), "discards " . sizeof($output) . " cards", $name);
            foreach ($output as $card_name) {
                $game->moveCardFromPileToPile($card_name, PlayHand, DiscardPile, $name);
            }

            $game->setPhase(Phase_Sleep, $name);
        }

        $game->cardActionFinished();
        return true;
    }

    public function getConditions() {
        return $this->reactConditions;
    }

    public function isReactRelevant(Game $game, $card, $name) {
        return true;
    }

    public function react(Game $game, $card, $name) {
        $game->addVictoryTokens(1, $name);
        ScreenDisplay::addScreenMessage($game, true, "activate ".  nicePrint($this), "activates ".  nicePrint($this), $name);
        ScreenDisplay::addScreenMessage($game, false, " and get 1 victory token ", " and gets 1 victory token ", $name);
    }

}

?>